/**   
 * @Title: BankCardBindingAct.java 
 * @Package com.esun.rabbit2.viewer.mainact.mylotteryact.banckbind 
 * @Description: 绑定银行卡界面 （包括已绑定和未绑定两种情况）
 * @author Miko baoz@500wan.com   
 * @date 2011-7-2 下午05:44:35  
 * copy right 深圳市易讯天空网络技术有限公司
 */
package com.esun.rabbit2.viewer.mainact.mylotteryact.banckbind;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.esun.config.Config;
import com.esun.config.ImageZhanJi;
import com.esun.network.ConnectionChangeReceiver;
import com.esun.rabbit2.communicaters.recharg.RechargeUserInfo;
import com.esun.ui.R;

/**
 * @ClassName: BankCardBindingAct
 * @Description: 绑定银行卡界面
 * @author Miko baoz@500wan.com
 * @date 2011-7-2 下午05:44:35
 * 
 */
public class BankCardBindingAct extends Activity implements OnClickListener {

	private ImageButton btnGoBack;
	private Bundle bundle;
	private TextView tv_bankname;
	private TextView tv_bankcardnum;
	private ImageView iv_bankLogo;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.bank_card_binding_act);
		init();

	}

	private void init() {
		tv_bankname = (TextView) findViewById(R.id.bank_card_binding_act_tv_bankName);
		tv_bankcardnum = (TextView) findViewById(R.id.bank_card_binding_act_tv_bankNum);
		iv_bankLogo = (ImageView) findViewById(R.id.bank_card_binding_act_iv_bankLogo);
		bundle = getIntent().getExtras();
		String TAG = bundle.getString("TAG");

		StringBuilder strShowNum = new StringBuilder();
		if (TAG.equals(Config.NUM0)) {

			String[] strCardNum = RechargeUserInfo.getUserInfo().getCardNum().split("|");
			for (int i = 0; i < strCardNum.length; i++) {
				if (i > 4 && i < strCardNum.length - 4) {
					strShowNum.append("*");
				} else {
					strShowNum.append(strCardNum[i]);
				}
			}
			tv_bankname.setText(RechargeUserInfo.getUserInfo().getBankName());
			tv_bankcardnum.setText(strShowNum.toString());
			showLogo(RechargeUserInfo.getUserInfo().getBankName());
		} else {
			String strCardNum = bundle.getString("cardNum");
			String strbankname = bundle.getString("bankname");
			for (int i = 0; i < strCardNum.length(); i++) {
				if (i > 4 && i < strCardNum.length() - 4) {
					strShowNum.append("*");
				} else {
					strShowNum.append(strCardNum.charAt(i));
				}
			}
			tv_bankname.setText(strbankname);
			tv_bankcardnum.setText(strShowNum.toString());
			showLogo(strbankname);
		}

		btnGoBack = (ImageButton) this.findViewById(R.id.bank_card_binding_act_btn_goBack);
		btnGoBack.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {

		this.finish();

	}

	@Override
	protected void onPause() {

		super.onPause();
		this.unregisterReceiver(ConnectionChangeReceiver.getConnectionChangeReceiver());
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		this.registerReceiver(ConnectionChangeReceiver.getConnectionChangeReceiver(), ConnectionChangeReceiver.getIntentFilter());
	}

	private void showLogo(String bankName) {
		ImageZhanJi image = ImageZhanJi.getInstace();
		if (bankName.contains("北京银行")) {
			iv_bankLogo.setBackgroundResource(image.getBankLogo(0));
		} else if (bankName.contains("工商银行")) {
			iv_bankLogo.setBackgroundResource(image.getBankLogo(1));
		} else if (bankName.contains("光大银行")) {
			iv_bankLogo.setBackgroundResource(image.getBankLogo(2));
		} else if (bankName.contains("华夏银行")) {
			iv_bankLogo.setBackgroundResource(image.getBankLogo(3));
		} else if (bankName.contains("建设银行")) {
			iv_bankLogo.setBackgroundResource(image.getBankLogo(4));
		} else if (bankName.contains("交通银行")) {
			iv_bankLogo.setBackgroundResource(image.getBankLogo(5));
		} else if (bankName.contains("民生银行")) {
			iv_bankLogo.setBackgroundResource(image.getBankLogo(6));
		} else if (bankName.contains("农业银行")) {
			iv_bankLogo.setBackgroundResource(image.getBankLogo(7));
		} else if (bankName.contains("浦发银行")) {
			iv_bankLogo.setBackgroundResource(image.getBankLogo(8));
		} else if (bankName.contains("深圳发展银行")) {
			iv_bankLogo.setBackgroundResource(image.getBankLogo(9));
		} else if (bankName.contains("兴业银行")) {
			iv_bankLogo.setBackgroundResource(image.getBankLogo(10));
		} else if (bankName.contains("邮政银行")) {
			iv_bankLogo.setBackgroundResource(image.getBankLogo(11));
		} else if (bankName.contains("招商银行")) {
			iv_bankLogo.setBackgroundResource(image.getBankLogo(12));
		} else if (bankName.contains("中国银行")) {
			iv_bankLogo.setBackgroundResource(image.getBankLogo(13));
		} else if (bankName.contains("中信银行")) {
			iv_bankLogo.setBackgroundResource(image.getBankLogo(14));
		} else {
			iv_bankLogo.setVisibility(View.GONE);
		}
	}
}
